package com.bc66.tiger.bizsys.menucategories.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
//import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

import com.bc66.tiger.bizsys.menucategories.model.MenuCategoriesBean; 
import com.bc66.tiger.framework.base.BaseRestSpringController;


@Controller
@RequestMapping("/testcontroller")
public class TestController extends BaseRestSpringController{

	@RequestMapping("/count")
	public ModelAndView count(HttpServletRequest request,HttpServletResponse response){
		
			
		System.out.println("rowcount 1:"+((SqlSessionFactory)this.getApplicationContext().
				getBean("sqlSessionFactory")).openSession().
				selectOne("com.bc66.tiger.bizsys.menucategories.model.mapper.MenuCategoriesBeanMapper.count"));
		
		
		
		return null;
		
	}
	
	@RequestMapping("/insert")
	public ModelAndView insert(HttpServletRequest request,HttpServletResponse response){
		
		MenuCategoriesBean mcb=new MenuCategoriesBean();
		
		mcb.setId(new Long("11111"));
		
		mcb.setMenuname("分类名");
		
		mcb.setEgname("English");
		
		mcb.setPinyin("fenleiming");
		
		mcb.setDiscription("这里是描述 测试描叙");
		
		mcb.setCreattime(new Date());
		
		mcb.setSort(new Long("10000"));
		
		mcb.setUserid(new Long("77777"));
		
		mcb.setShopid(new Long("77777"));
		
		System.out.println(((SqlSessionFactory)getApplicationContext().getBean("sqlSessionFactory"))==null);
		System.out.println("<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>"+((SqlSessionFactory)getApplicationContext().getBean("sqlSessionFactory")).openSession()
				.selectOne("com.bc66.tiger.bizsys.menucategories.model.mapper.MenuCategoriesBeanMapper.count"));
		((SqlSessionFactory)getApplicationContext().getBean("sqlSessionFactory")).openSession()
		.insert("com.bc66.tiger.bizsys.menucategories.model.mapper.MenuCategoriesBeanMapper.newCategories", mcb);
		((SqlSessionFactory)getApplicationContext().getBean("sqlSessionFactory")).openSession().commit();
		return null;
	}
	
	@RequestMapping("/update")
	public ModelAndView update(HttpServletRequest request,HttpServletResponse response){
		
		MenuCategoriesBean mcb=new MenuCategoriesBean();
		
		mcb.setId(new Long("100000000015"));
		
		mcb.setMenuname("分类名change");
		
		mcb.setEgname("Englishchange");
		
		mcb.setPinyin("fenleimingchange");
		
		mcb.setDiscription("这里是描述 测试描叙change");
		
		mcb.setCreattime(new Date());
		
		mcb.setSort(new Long("10001"));
		
		((SqlSessionFactory)getApplicationContext().getBean("sqlSessionFactory")).openSession()
		.update("com.bc66.tiger.bizsys.menucategories.model.mapper.MenuCategoriesBeanMapper.updateCategories", mcb);
		
		return null;
	}
	
	@RequestMapping("/delete")
	public ModelAndView delete(HttpServletRequest request,HttpServletResponse response){
		
		MenuCategoriesBean mcb=new MenuCategoriesBean();
		
		mcb.setId(new Long("100000000016"));
				
		((SqlSessionFactory)getApplicationContext().getBean("sqlSessionFactory")).openSession()
		.delete("com.bc66.tiger.bizsys.menucategories.model.mapper.MenuCategoriesBeanMapper.delCategories", mcb);
		
		return null;
	}
	
	@RequestMapping("/offerlist")
	public ModelAndView offerlist(HttpServletRequest request,HttpServletResponse response){
		
		MenuCategoriesBean mcb=new MenuCategoriesBean();
		
		
		
		mcb.setId(new Long("7777777777778"));
				
		System.out.println(
				((SqlSessionFactory)getApplicationContext().getBean("sqlSessionFactory")).openSession()
		.selectList("com.bc66.tiger.bizsys.menucategories.model.mapper.MenuCategoriesBeanMapper.offsetCategories", 
				mcb,new RowBounds(0,2)).size());
		
		return new ModelAndView("test");
	}
	
}
